package com.yingxue.lesson.controller;/*
 * @date:2021/6/19 20:16
 * @author: dzj
 **/

import com.yingxue.lesson.entity.SysDept;
import com.yingxue.lesson.service.DeptService;
import com.yingxue.lesson.utils.DataResult;
import com.yingxue.lesson.vo.req.DeptAddReqVO;
import com.yingxue.lesson.vo.resp.DeptRespNodeVO;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import javax.validation.Valid;
import java.util.List;

@RequestMapping("/api")
@RestController
@Api(tags = "组织模块-机构管理")
public class DeptController {
    @Autowired
    private DeptService deptService;
    @GetMapping("/depts")
    @ApiOperation(value = "获取所有部门数据接口")
    public DataResult<List<SysDept>> getDeptAll(){
        DataResult result= DataResult.success();
        result.setData(deptService.selectAll());
        return result;
    }
    @GetMapping("/dept/tree")
    @ApiOperation(value = "树型部门列表接口")
    public DataResult<List<DeptRespNodeVO>> getDeptTree(){
        DataResult result=DataResult.success();
        result.setData(deptService.deptTreeList());
        return result;
    }
    @PostMapping("/dept")
    @ApiOperation(value = "新增部门接口")
    public DataResult<SysDept> addDept(@RequestBody @Valid DeptAddReqVO vo){
        DataResult<SysDept> result=DataResult.success();
        result.setData(deptService.addDept(vo));
        return result;
    }
}
